console.log(111);
// 通过jsonp请求后端资源
let data = [];
function jsonp(res){
    data = res;
    console.log(data)//这里拿到数据了
}
function getData(){
    const ss = document.createElement('script');

    ss.src='http://localhost:9527/api/student/jsonpData/345'
    ss.onload= function(){
       // 删除元素
       ss.remove();
    }
    document.body.appendChild(ss)

}
// getData()
btn1.onclick =function(){
    console.log("点击率")
    fetch("http://localhost:9527/login/345").then((resp)=>resp.json()).then((resp)=>
    console.log("结果",resp))
}
btn11.onclick =function(){
    console.log("点击率")
    fetch("/login/345").then((resp)=>resp.json()).then((resp)=>
    console.log("结果",resp))
}

const base = {
    loginId:'admin',
    loginPwd:'123123',
}
btn2.onclick =function(){
    fetch("http://localhost:9527/login",{
        method:"POST",
        headers:{  // 设置请求头
            "content-type": "application/x-www-form-urlencoded"
          },
        body:`loginId=admin&&loginPwd=123123`
    }).then(resp=>resp.json()).then(resp=>{
        console.log("登录结果",resp)
    })
}
// 注意以上的情况是可以请求到数据的

// 现在尝试一下需要预检的请求

btn3.onclick = function(){
    fetch("http://localhost:9527/login",{
        method:"POST",
        headers:{  // 设置请求头
            "content-type":"application/json"
          },
        body:JSON.stringify(base)
    }).then(resp=>resp.json()).then(resp=>{
        console.log("需要预检登录结果",resp)
    })
}

btn4.onclick = function(){
    fetch("http://localhost:9527/login/456/",{
        method:"DELETE",
        credentials: "include",
        headers:{
            a:'1'
        }
    }).then((resp)=>resp.json()).then((resp)=>{
        console.log(resp)
    })
}

btn5.onclick = function(){
    fetch("http://localhost:9527/login/456").then(resp=>resp.json()).then(resp=>{
        console.log(resp)
    })
}